package cn.zhangxin.newyear.system.employee.service.impl;

import cn.zhangxin.newyear.base.query.BaseQuery;
import cn.zhangxin.newyear.system.employee.domain.Employee;
import cn.zhangxin.newyear.system.employee.domain.EmployeeBO;
import cn.zhangxin.newyear.system.employee.mapper.EmployeeMapper;
import cn.zhangxin.newyear.system.employee.service.IEmployeeService;
import cn.zhangxin.newyear.base.service.impl.BaseServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zx
 * @since 2023-01-19
 */
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public List<Employee> findAllBO() {
        List<EmployeeBO> empBO = employeeMapper.findAllBO();
        List<Employee>  employees= new ArrayList();
        for (EmployeeBO employeeBO: empBO){
            Employee employee = new Employee();
            BeanUtils.copyProperties(employeeBO,employee);
            employees.add(employee);
            //BeanUtils.copyProperties(list,employee); list:源数据 employee:目标对象
        }
        return employees;
    }

    @Override
    public List<Employee> findByQuery(BaseQuery baseQuery) {
        List<Employee> byQuery = employeeMapper.findByQuery(baseQuery);
        List<Employee>  employees= new ArrayList();
        for (Employee e : byQuery){
            e.setSalt(null);
            e.setPassword(null);
            Employee employee = new Employee();
            BeanUtils.copyProperties(e,employee);
            employees.add(employee);
        }
        return employees;
    }
}
